package cn.ctodb.mall.goods.service.mapper;

import cn.ctodb.mall.goods.domain.*;
import cn.ctodb.mall.goods.service.dto.AttributeDTO;

import org.mapstruct.*;
import java.util.List;

/**
 * Mapper for the entity Attribute and its DTO AttributeDTO.
 */
@Mapper(componentModel = "spring", uses = {CategoryMapper.class, })
public interface AttributeMapper {

    @Mapping(source = "category.id", target = "categoryId")
    AttributeDTO attributeToAttributeDTO(Attribute attribute);

    List<AttributeDTO> attributesToAttributeDTOs(List<Attribute> attributes);

    @Mapping(source = "categoryId", target = "category")
    Attribute attributeDTOToAttribute(AttributeDTO attributeDTO);

    List<Attribute> attributeDTOsToAttributes(List<AttributeDTO> attributeDTOs);
    /**
     * generating the fromId for all mappers if the databaseType is sql, as the class has relationship to it might need it, instead of
     * creating a new attribute to know if the entity has any relationship from some other entity
     *
     * @param id id of the entity
     * @return the entity instance
     */
     
    default Attribute attributeFromId(Long id) {
        if (id == null) {
            return null;
        }
        Attribute attribute = new Attribute();
        attribute.setId(id);
        return attribute;
    }
    

}
